package projectjet;

import java.io.IOException;
import java.net.ServerSocket;

public class ServerChat {
	private ServerSocket serverSocket;
	
	public ServerChat(int port) throws Exception{
		try {
			System.out.println("Binding to port " + port);
			this.serverSocket = new ServerSocket(port);
			System.out.println("Server started ");
			System.out.println("Waiting connections...");
		} catch (IOException e) {
			throw new Exception("Error creating connection with port " + port + ": " + e.getMessage());
		}
	}

	public void run(){
		while(true){
			try {
				new Session(serverSocket.accept()).start();
			} catch (IOException e) {
				System.out.println("Connection error: " + e.getMessage());
			}
		}
	}
	
	public static void main(String[] args) throws Exception {
		ServerChat serverChat = new ServerChat(3000);
		serverChat.run();
	}
}
